layui.use(['form', 'jquery', 'layer'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery;

    $("#closeBtn").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });

    var level = $("#level").val()
    if (level != null && level != "") {
        $("#supplierLevel option").each(function () {
            if (level == $(this).val()) {
                $(this).prop("selected", "selected");
                form.render("select");
            }
        })
    }
    // 加载主要产品
    $.ajax({
        type: "get",
        url: ctx + "/supplier/queryMainMaterialInSupplier?supplierId=" + $('input[name="id"]').val(),
        data: {},
        success: function (data) {
            if (data != null) {
                $.each(data, function (index, item) {
                    $('#supplierMainCommodityId').append(new Option(item.name, item.id));
                    $('#supplierMainCommodityId').val($("#mainCustomer").val())
                })
                form.render(); //更新全部表单内容
            }
        }
    });
    form.on('submit(updateSupplierFilter)', function (data) {

        var index = top.layer.msg("数据提交中，请稍后", {
            icon: 16, // 图标
            time: true,  // 不关闭
            shade: 0.8 // 设置遮罩透明度
        });

        var formData = data.field;
        var url = ctx + "/supplier/updateSupplier";
        $.post(url, formData, function (data) {
            if (data.code == 200) {
                layer.msg(data.msg, {icon: 6});
                layer.close(index)
                layer.closeAll("iframe")
                parent.location.reload();
            } else {
                layer.msg(data.msg, {icon: 5})
            }
        })
        return false;
    })


})